// 自己写的代码9/10
#include <bits/stdc++.h>
using namespace std;
const int N = 5000;
int n, nums[N];
int ans = 0, sum = 0, d[N];
int main()
{
	int x;

	while (cin >> x)
	{
		n++;
		nums[n] = x;
		// cout<<nums[n];
	}

	for (int i = 1; i <= n - 1; i++)
	{
		d[i] = nums[i + 1] - nums[i];
		// cout<<"d[i]="<<d[i]<<"\n";
	}
	for (int i = 1; i <= n; i++)
	{
		if (d[i] == d[i + 1]) // 三个数相等
		{
			sum++;
			// cout<<"sum1="<<sum<<"\n";
		}
		if (d[i] != d[i + 1] || i > n)
		{
			for (int j = 1; j <= sum; j++)
			{
				// cout<<"sum="<<sum<<"\n";
				ans = ans + j;
				// cout<<"ans="<<ans;
			}

			sum = 0;
		}
	}
	cout << ans;
	return 0;
}
/*参考题解：
#include <bits/stdc++.h>
using namespace std;
const int N = 5010;
int n, nums[N];
int ans = 0, d[N];
int main()
{
	int x;

	while (cin >> x)
	{
		n++;
		nums[n] = x;
		d[n] = nums[n] - nums[n - 1];
	}

	for (int i = 2; i < n; i++)//遍历数组d，找出连续相等的数字序列，并累加其个数到变量ans中。最后输出结果ans。
	{
		int tmp = d[i], index = i + 1, t = 0;
		while (d[index] == tmp)
		{
			t++;
			index++;
		}
		ans += t;
	}

	cout << ans;
	return 0;
}

*/
